﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace BT_web__nhom06
{
    public partial class Sua_User : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string username = Request.QueryString["Username"];

            if(username == null)  //kiem tra dieu kien Null de tranh bao loi ko co tham so
            {
                Response.Redirect("QuanLyTaiKhoan.aspx");
            }
            
            DataTable tbl = Tienichsql.ketnoicsdl.ChayLenhSelectDuLieu("SELECT * FROM [User] where username=@username", "@username", username);
            DataRow dr = tbl.Rows[0];
            txtUsername.Text = dr["Username"].ToString();
            txtMasinhvien.Text = dr["MaHS"].ToString();
            bool locked =(bool) dr["Locked"];
            if (locked)
                cbxKhoa.Checked = true;
            else 
               cbxKhoa.Checked = false;
            txtthoidiemdncuoi.Text = dr["ThoiDiemDangNhapCuoi"].ToString();
            txtip.Text = dr["IPMayDangNhapCuoi"].ToString();
            txtmac.Text = dr["MACMayDangNhapCuoi"].ToString();
            drlquyen.SelectedValue = dr["Quyen"].ToString();
        }

        protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
        {

        }

        protected void CheckBox1_CheckedChanged1(object sender, EventArgs e)
        {

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            string username = Request.QueryString["Username"];
            int ketqua = 0;
            if (username != null)
            {
                bool locked = true;
                if (cbxKhoa.Checked == true)
                    locked = false;
        
                string quyen= drlquyen.SelectedIndex.ToString();
                string lenhsql = "update [User] set [locked]=@locked, [quyen]=@quyen where [username] = @username";
              
                    ketqua = Tienichsql.ketnoicsdl.chaylenhcapnhatdulieu(lenhsql, new string[] { "@locked","@quyen","@username" }, new object[] { locked, quyen,username });
          
                if (ketqua == 1)
                    lblcapnhat.Text = "cap nhat thanh cong!";
                else
                    lblcapnhat.Text = "cap nhat khong thanh cong!";
       
            }
        }

      
        protected void btnthoat_Click1(object sender, EventArgs e)
        {
            Response.Redirect("QuanLyTaiKhoan.aspx");
        }
    }
}